/**
 * 
 */
package vista.ventanas;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPanel;

import domain.Juego;

import business.Controlador;

/**
 * @author De La
 *
 */
public class PanelPrincipal extends JPanel {
	
	public PanelPrincipal() {
		setLayout( new GridBagLayout() );
		GridBagConstraints ct = new GridBagConstraints();
		
		//Agrego el PanelPizarra:
		ct.gridx = 0;
		ct.gridy = 0;
		ct.gridwidth = 2;
		ct.fill = GridBagConstraints.BOTH;
		ct.weightx = 1;
		ct.weighty = 0.9;
		ct.insets = new Insets(1,1,1,1);
		add( PanelPizarra.getInstance(), ct );
		
		//Agrego el Boton Limpiar:
		JButton bClear = new JButton();
		bClear.setText("Limpiar");
		bClear.addActionListener( new bClearAction() );
		ct.gridy = 1;
		ct.weighty = 0;
		ct.weightx = 0;
		ct.gridwidth = 1;
		ct.fill = GridBagConstraints.NONE;
		ct.anchor = GridBagConstraints.NORTHWEST;
		add(bClear, ct);
		
		//Agrego el Boton Prueba:
		JButton bPrueba = new JButton();
		bPrueba.setText("Prueba");
		bPrueba.addActionListener( new bPruebaAction() );
		ct.gridx = 1;
		ct.gridy = 1;
		ct.weighty = 0;
		ct.fill = GridBagConstraints.NONE;
		ct.anchor = GridBagConstraints.NORTHWEST;
		add(bPrueba, ct);
	}
	
	private class bClearAction implements ActionListener {
		public void actionPerformed(ActionEvent arg0) {
			Controlador.getInstance().limpiar();
			PanelPizarra.getInstance().setDibujando(false);
			PanelPizarra.getInstance().setLastPosition(null);
			repaint();
		}
	}
	
	private class bPruebaAction implements ActionListener {
		public void actionPerformed(ActionEvent arg0) {
			Juego.getInstance().getPizarra().setUltimoPunto( new Point(300,300) );
			Controlador.getInstance().addPunto( new Point(400,300), false );
			Juego.getInstance().getPizarra().setUltimoPunto( new Point(300,300) );
			Controlador.getInstance().addPunto( new Point(300,200), false );
			Juego.getInstance().getPizarra().setUltimoPunto( new Point(300,300) );
			Controlador.getInstance().addPunto( new Point(200,300), false );
			Juego.getInstance().getPizarra().setUltimoPunto( new Point(300,300) );
			Controlador.getInstance().addPunto( new Point(300,400), false );
			
			Juego.getInstance().getPizarra().setUltimoPunto( new Point(200,200) );
			Controlador.getInstance().addPunto( new Point(400,400), false );
			Juego.getInstance().getPizarra().setUltimoPunto( new Point(400,200) );
			Controlador.getInstance().addPunto( new Point(200,400), false );
			
			Juego.getInstance().getPizarra().setUltimoPunto( new Point(500,300) );
			Controlador.getInstance().addPunto( new Point(600,300), false );
			Controlador.getInstance().addPunto( new Point(600,400), false );
			Controlador.getInstance().addPunto( new Point(500,400), false );
			Controlador.getInstance().addPunto( new Point(500,300), false );
			
			repaint();
		}
	}
	
}
